/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.autosalon.ui.customer.action;

import com.autosalon.ui.customer.Customer;
import com.autosalon.ui.customer.state.CustomerStateHolder;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;

/**
 *
 * @author Kubík
 */
public class RemoveAdressAction extends AbstractCustomerAction implements Button.ClickListener {

    public RemoveAdressAction(Customer customer) {
        super(customer);
    }

    @Override
    public void buttonClick(ClickEvent event) {
        int countOfAdress = customer.getCountOfAdress() - 1;
        customer.setCountOfAdress(countOfAdress);
        customer.getNewAdress().remove(customer.getNewAdress().size() - 1);
        customer.addComponent();

        int id;
        try {
            id = customer.getSwitcher().getMainWindow().getZakaznik().getRole().getId().intValue();
        } catch (NullPointerException e) {
            id = 1;
        }
        int no=customer.getNewAdress().size();
        if (customer.getNewAdress().size() <= 1) {
            CustomerStateHolder.setState(CustomerStateHolder.NO_MORE_ADRESS_STATE, id, customer);
        } else {
            CustomerStateHolder.setState(CustomerStateHolder.ADD_ADRESS_STATE, id, customer);
        }

    }
}
